package com.joysuch.wwyt.bp.controller;


import com.joysuch.wwyt.bp.bean.inspect.BPInspectItemTypeBean;
import com.joysuch.wwyt.bp.entity.inspect.BPInspectItemType;
import com.joysuch.wwyt.bp.service.BPInspectItemService;
import com.joysuch.wwyt.bp.service.BPInspectItemTypeService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bp/inspect-itemType")
@Api(tags = "巡检点-检查项目类型管理")
@CrossOrigin
public class BPInspectItemTypeController {

    @Autowired
    private BPInspectItemTypeService inspectItemTypeService;

    @Autowired
    private BPInspectItemService inspectItemService;

    @GetMapping("/list")
    @ApiOperation(value = "01 巡检项类型列表", response = BPInspectItemType.class)
    public ResultBean list() {
        List<BPInspectItemType> typeList = inspectItemTypeService.findList();
        return ResultBean.success(typeList);

    }

    @PostMapping("/save")
    @RequiresPermissions("bp:inspect-itemType:save")
    @ApiOperation(value = "02 保存巡检项类型", response = BPInspectItemType.class)
    public ResultBean save(@RequestBody BPInspectItemTypeBean bean) {
        ResultBean resultBean = inspectItemTypeService.save(bean);
        return resultBean;
    }


    @GetMapping("/getById/{id}")
    @RequiresPermissions("bp:inspect-itemType:get")
    @ApiOperation(value = "03 根据巡检项类型ID获取详情", response = BPInspectItemType.class)
    @ApiImplicitParam(name = "id", value = "巡检项类型ID", paramType = "path", required = true)
    public ResultBean getById(@PathVariable Long id) {
        BPInspectItemType inspectItemType = inspectItemTypeService.getById(id);
        return ResultBean.success(inspectItemType);

    }

    @GetMapping("/delete/{id}")
    @RequiresPermissions("bp:inspect-itemType:delete")
    @ApiOperation(value = "04 根据巡检项类型ID删除")
    @ApiImplicitParam(name = "id", value = "巡检项类型ID", paramType = "path", required = true)
    public ResultBean delete(@PathVariable Long id) {
        inspectItemTypeService.deleteById(id);
        return ResultBean.defaultSuccessResult();

    }

}
